﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LoginViewModelTest.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Summary description for LoginViewModelTest
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Client.Desktop.Tests.ViewModel
{
    using System.Reflection;

    using Hisaab.Business.Interfaces;
    using Hisaab.Client.Desktop.Commands;
    using Hisaab.Client.Desktop.Properties;
    using Hisaab.Client.Desktop.ViewModel;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Moq;

    /// <summary>
    /// Defines the <seealso cref="LoginViewModelTest"/> type.
    /// </summary>
    [TestClass]
    public class LoginViewModelTest
    {
        /// <summary>
        /// Logins the command should return login command object.
        /// </summary>
        [TestMethod]
        public void LoginCommandShouldReturnLoginCommandObject()
        {
            var mockLocator = new MockServiceLocator();
            var mockService = new Mock<IUserManager>();

            mockLocator.SetInjection(mockService.Object);

            var vm = new LoginViewModel();
            Assert.IsInstanceOfType(vm.LoginCommand, typeof(LoginCommand));
        }

        /// <summary>
        /// Cancels the command should return cancel command object.
        /// </summary>
        [TestMethod]
        public void CancelCommandShouldReturnExitCommandObject()
        {
            var vm = new LoginViewModel();

            Assert.IsInstanceOfType(vm.CancelCommand, typeof(ExitCommand));
        }

        /// <summary>
        /// Apps the name should have default value from resource.
        /// </summary>
        [TestMethod]
        public void AppNameShouldHaveDefaultValueFromResource()
        {
            var vm = new LoginViewModel();
            Assert.AreEqual(Resources.ApplicationName, vm.AppName);
        }

        /// <summary>
        /// Apps the name should raise property change event.
        /// </summary>
        [TestMethod]
        public void AppNameShouldRaisePropertyChangeEvent()
        {
            var vm = new LoginViewModel();
            var changeTester = new NotifyPropertyChangedTester(vm);

            vm.AppName = "New Application Name";

            changeTester.AssertChange(0, "AppName");
        }

        /// <summary>
        /// Copyrights the should have default value from resource.
        /// </summary>
        [TestMethod]
        public void CopyrightShouldHaveDefaultValueFromResource()
        {
            var vm = new LoginViewModel();
            Assert.AreEqual(Resources.CopyRightString, vm.Copyright);
        }

        /// <summary>
        /// Copyrights the should raise property change event.
        /// </summary>
        [TestMethod]
        public void CopyrightShouldRaisePropertyChangeEvent()
        {
            var vm = new LoginViewModel();
            var changeTester = new NotifyPropertyChangedTester(vm);

            vm.Copyright = "New copyright";

            changeTester.AssertChange(0, "Copyright");
        }

        /// <summary>
        /// Messages the should raise property change event.
        /// </summary>
        [TestMethod]
        public void MessageShouldRaisePropertyChangeEvent()
        {
            var vm = new LoginViewModel();
            var changeTester = new NotifyPropertyChangedTester(vm);

            vm.Message = "A message for test";

            changeTester.AssertChange(0, "Message");
        }

        /// <summary>
        /// Versions the string should have default value from assembly.
        /// </summary>
        public void VersionStringShouldHaveDefaultValueFromAssembly()
        {
            var vm = new LoginViewModel();
            Assert.AreEqual(Assembly.GetExecutingAssembly().GetName().Version.ToString(), vm.VersionString);
        }

        /// <summary>
        /// Versions the string should raise property change event.
        /// </summary>
        [TestMethod]
        public void VersionStringShouldRaisePropertyChangeEvent()
        {
            var vm = new LoginViewModel();
            var changeTester = new NotifyPropertyChangedTester(vm);

            vm.VersionString = "3.2";

            changeTester.AssertChange(0, "VersionString");
        }
    }
}